﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TheMovieDB;
using System.IO;

namespace tmdbClient
{
    public class MdbMovie
    {
        private string path = string.Empty;
        private string name = string.Empty;
        private bool hasFolderJpg = false;
        private bool hasFanartJpg = false;
        private bool hasMovieXml = false;
        private TmdbAPI tmdb = null;
        private TmdbMovie[] possibilities = null;
        private TmdbMovie current = null;

        #region eigenschaften

        /// <summary>
        /// Pfad zum Film
        /// </summary>
        public string Path
        {
            get 
            { 
                return this.path; 
            }
            set 
            { 
                this.path = value;
                this.name = this.path.Substring(this.path.LastIndexOf(@"\") + 1);
                
                if (File.Exists(path + "\\folder.jpg"))
                {
                    this.hasFolderJpg = true;
                }

                if (File.Exists(path + "\\fanart.jpg"))
                {
                    this.hasFanartJpg = true;
                }

                if (File.Exists(path + "\\movie.xml"))
                {
                    this.hasMovieXml = true;
                }
            }
        }

        /// <summary>
        /// Der Name des Films
        /// </summary>
        public string Name
        {
            get { return this.name; }
        }

        /// <summary>
        /// Zeigt an, ob die Datei "folder.jpg" im Verzeichnis des Fils vorhanden ist vorhanden ist
        /// </summary>
        public bool HasFolderJpg
        {
            get { return this.hasFolderJpg; }
        }

        /// <summary>
        /// Zeigt an, ob die Datei "fanart.jpg" im Verzeichnis des Fils vorhanden ist vorhanden ist
        /// </summary>
        public bool HasFanartJpg
        {
            get { return this.hasFanartJpg; }
        }

        /// <summary>
        /// Zeigt an, ob die Datei "movie.xml" im Verzeichnis des Fils vorhanden ist vorhanden ist
        /// </summary>
        public bool HasMovieXml
        {
            get { return this.hasMovieXml; }
            set { this.hasMovieXml = value; }
        }

        /// <summary>
        /// Sammlung möglicher Ergebnisse zu einer Suchanfrage
        /// </summary>
        public TmdbMovie[] Possibilities
        {
            get 
            { 
                return this.possibilities; 
            }
            set 
            { 
                this.possibilities = value;
                if (this.possibilities.Length == 1)
                {
                    this.current = this.possibilities[0];
                }
            }
        }

        /// <summary>
        /// Der konkrete Film
        /// </summary>
        public TmdbMovie Current
        {
            get { return this.current; }
            set { this.current = value; }
        }

        #endregion

        #region Konstruktor

        public MdbMovie(string path, TmdbAPI api)
        {
            this.Path = path;
            this.tmdb = api;
        }

        #endregion

        #region Public

        public void GetMovieInfos()
        {
            this.Possibilities = this.tmdb.MovieSearch(this.name);
        }

        #endregion
    }
}
